#pragma once

#include <gofcl_usbfs_r.h>

typedef struct {
	u32_s CNUM : 4;
	u32_s BCOUNT : 11;
	u32_s DPID : 2;
	u32_s RPCKST : 4;
	u32_s : 11;
} usbfs_grstat_host_s;

_Static_assert(sizeof(usbfs_grstat_host_s) == 4,
	       "Struct usbfs_grstat_host_s defined error!");

static inline void usbfs_wreg_grstatr_host_s(usbfs_grstat_host_s grstat) {
	union {
		usbfs_grstat_host_s g;
		u32_s u;
	} gu = {
		.g = grstat,
	};
	usbfs_wreg(USBFS_GRSTATR_R, gu.u);
}

static inline usbfs_grstat_host_s usbfs_rreg_grstatr_host_s(void) {
	union {
		usbfs_grstat_host_s g;
		u32_s u;
	} gu = {
		.u = usbfs_rreg(USBFS_GRSTATR_R),
	};
	return gu.g;
}

static inline void usbfs_wreg_grstatp_host_s(usbfs_grstat_host_s grstat) {
	union {
		usbfs_grstat_host_s g;
		u32_s u;
	} gu = {
		.g = grstat,
	};
	usbfs_wreg(USBFS_GRSTATP_R, gu.u);
}

static inline usbfs_grstat_host_s usbfs_rreg_grstatp_host_s(void) {
	union {
		usbfs_grstat_host_s g;
		u32_s u;
	} gu = {
		.u = usbfs_rreg(USBFS_GRSTATP_R),
	};
	return gu.g;
}
